package com.snopy.concurrency.atomic;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.DoubleAccumulator;
import java.util.concurrent.atomic.DoubleAdder;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author snopy
 * @version 1.0.0
 * @classname AccumilatorDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/06/28 21:06
 */
@Slf4j
public class AccumulatorDemo {

    public static void main(String[] args) {
        LongAccumulator  accumulator = new LongAccumulator(Long::sum,1);
        accumulator.accumulate(1);
        DoubleAccumulator doubleAccumulator = new DoubleAccumulator(Double::sum,2.0);
        doubleAccumulator.accumulate(2.0);
        log.info("{}",accumulator.get());
        log.info("{}",doubleAccumulator.get());
        DoubleAdder doubleAdder = new DoubleAdder();
        doubleAdder.add(30.0);
        doubleAdder.add(3);
        log.info("{}",doubleAdder.doubleValue());

        LongAdder longAdder = new LongAdder();
        longAdder.add(10);
        longAdder.add(3);
        log.info("{}",longAdder.sumThenReset());
        log.info("{}",longAdder.sum());

        log.info("0&1:{}",128&1);
    }
}
